
#include "view_time_0.h"
#include "app_trace.h"
#include "battery_ctrl.h"
#include "blecom.h"
#include "datetime.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "heart_rate_interface.h"
#include "lfs_file_manager_auto.h"
#include "platform_assert.h"
#include "rtc.h"
#include "sport_his.h"
#include "view_common.h"
#include "view_time_0.inc"
#define LOG(fmt, ...) // app_trace_log(fmt "\r\n", ##__VA_ARGS__)

void show_time_0_battery(int battery)
{
    disp_draw_user_image_filter_color(115, 7, img_time_0_percentage);

    uint16_t x = 108;
    uint16_t y = 7;
    uint8_t front_width = 5;
    uint8_t front_spacing = 1;

    if (battery < 0)
    {
        battery = 0;
        disp_draw_user_image(x, y, img_time_0_battery_num_TAB[battery]);
    }

    int length = get_num_digit(battery);
    LOG("%d", length);
    for (uint8_t i = 0; i < length; i++)
    {
        disp_draw_user_image_filter_color(x, y, img_time_0_battery_num_TAB[battery % 10]);
        x -= (front_width + front_spacing);
        battery /= 10;
    }
}
void show_time_0_ble_with_xy(bool connect, int x, int y)
{
    if (connect)
    {
        disp_draw_user_image_filter_color(x, y, img_ble_connect);
    }
    else
    {
        disp_draw_user_image_filter_color(x, y, img_ble_disconnect);
    }
}
void show_time_0_ble(bool connect)
{
    show_time_0_ble_with_xy(connect, 3, 0);
}
#if defined(TIME_0_SKIP)
#else
static void view_time_0_time(void)
{
    disp_draw_user_image_filter_color(69, 33, img_time_0_time_num_TAB[disp_ctrl.com_data.i_temp[3] / 10]);
    disp_draw_user_image_filter_color(95, 33, img_time_0_time_num_TAB[disp_ctrl.com_data.i_temp[3] % 10]);
    disp_draw_user_image_filter_color(69, 83, img_time_0_time_num_TAB[disp_ctrl.com_data.i_temp[4] / 10]);
    disp_draw_user_image_filter_color(95, 83, img_time_0_time_num_TAB[disp_ctrl.com_data.i_temp[4] % 10]);
}

void view_time_0_display(void)
{
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, 2, 39, FILE_IMG_dial_1_back);
    view_time_0_time();
    show_time_0_ble(disp_ctrl.com_data.i_temp[6]);
    show_time_0_battery(disp_ctrl.com_data.i_temp[7]);
}
#endif
